home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJINC106.ARJ / STRSTREA.H < prev    next >
C/C++ Source or Header  |  1992-03-29  |  3KB  |  75 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef __STRSTREAM_H
  19. #define __STRSTREAM_H
  20. #ifdef __GNUG__
  21. #pragma interface
  22. #endif
  23. #include <iostream.h>
  24.  
  25. class strstreambuf : public streambuf {
  26.     _G_size_t _len; // The current length is max(_len, _pptr-_pbase).
  27.     _G_size_t _size; // Allocated (physical) buffer size.
  28.     char *_buffer;
  29.     int _frozen;
  30.   protected:
  31.     virtual int overflow(int = EOF);
  32.     virtual int underflow();
  33.   public:
  34.     strstreambuf();
  35.     strstreambuf(int initial);
  36.     strstreambuf(char *ptr, int size, char *pstart = NULL);
  37.     ~strstreambuf();
  38.     int frozen() { return _frozen; }
  39.     void freeze(int n=1) { _frozen = n != 0; }
  40.     _G_size_t pcount();
  41.     char *str();
  42.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  43. };
  44.  
  45. class istrstream : public istream {
  46.   public:
  47.     istrstream(char*);
  48.     istrstream(char*, int);
  49.     strstreambuf* rdbuf() { return (strstreambuf*)_strbuf; }
  50. };
  51.  
  52. class ostrstream : public ostream {
  53.   public:
  54.     ostrstream();
  55.     ostrstream(char *cp, int n, int mode=ios::out);
  56.     _G_size_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
  57.     char *str() { return ((strstreambuf*)_strbuf)->str(); }
  58.     void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
  59.     int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
  60.     strstreambuf* rdbuf() { return (strstreambuf*)_strbuf; }
  61. };
  62.  
  63. class strstream : public iostream {
  64.   public:
  65.     strstream();
  66.     strstream(char *cp, int n, int mode);
  67.     _G_size_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
  68.     char *str() { return ((strstreambuf*)_strbuf)->str(); }
  69.     void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
  70.     int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
  71.     strstreambuf* rdbuf() { return (strstreambuf*)_strbuf; }
  72. };
  73.  
  74. #endif /*!__STRSTREAM_H*/
  75.